package com.yzy.fly.config;

import com.yzy.fly.api.function.listener.filter.TrackIdFilter;
import com.yzy.fly.config.properties.FlyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {


    @Autowired(required = false)
    private FlyProperties flyProperties;


    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        TrackIdFilter trackIdFilter = new TrackIdFilter(flyProperties);
//        trackIdFilter.setExcludes(Lists.newArrayList(".gif",".png",".jpg",".jpeg",".js",".css",".log", "log/query"));

        filterRegistrationBean.setFilter(trackIdFilter);
        filterRegistrationBean.addUrlPatterns("/*");
        // 过滤器名称
        filterRegistrationBean.setName("logMDCFilter");
        // 过滤器顺序
        filterRegistrationBean.setOrder(0);
        return filterRegistrationBean;
    }
}

